package com.yubest.demo.handler.impl;

import cn.hutool.core.math.MathUtil;
import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import com.yubest.demo.handler.Const;
import com.yubest.demo.handler.Handler;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author hweiyu
 * @Description
 * @Date 2021/8/12 10:28
 */
public class BaseHandler implements Handler {

    public String getPassword(String path, String password) {
        return null;
    }

    @Override
    public String exec(String path) {
        for (int i = 1; i <= 10; i++) {
            System.out.println("======当前密码位数： " + i);
            List<String> pList = this.getList(i);
            for (String p : pList) {
                String pwd = this.getPassword(path, p);
                if (null != pwd) {
                    return pwd;
                }
            }
        }
        return null;
    }

    private static List<String> getList(int length) {
        List<String> result = new ArrayList<>();
        String s = Const.NUMBER + Const.ALPHABET + Const.SYMBOL;
        String[] arr = s.split("");
        List<String[]> x = MathUtil.arrangementSelect(arr, length);
        for (String[] strings : x) {
            result.add(String.join("", strings));
        }
        return result;
    }

    public static void main(String[] args) throws SQLException {
//        System.out.println(new BaseHandler().getList(3).size());
//        List<Entity> result = Db.use().query("select * from secret");

//        List<String> x = getList(1);
//        for (int i = 0; i < x.size(); i += 100) {
//            List<String> subList = x.subList(i, Math.min(x.size(), i + 100));
//            List<Entity> sub = new ArrayList<>();
//            for (String s : subList) {
//                sub.add(Entity.create("secret").set("secret", s));
//            }
//            Db.use().insert(sub);
//        }
//        System.out.println();

        String s = Const.NUMBER + Const.ALPHABET + Const.SYMBOL;
        String[] arr = s.split("");
        for (String s1 : arr) {
            for (String s2 : arr) {
                for (String s3 : arr) {
                    System.out.println("当前：" + s1 + s2 + s3);
                    Db.use().insert(Entity.create("secret").set("secret", s1 + s2 + s3));
                }
            }
        }
    }

}
